import re
# a = 'abasabcdfghABcjklgakjv'
# result = re.match('aba',a)
# print(result)
# s = re.sub('ab','AKA',a,re.I)
# print(s)




# pattern:填写正则表达式
# string:在那个字符串中去查找
# flags:标识位
# 【1】从首位开始一一匹配,.知道匹配一次就停
# result=re.match(pattern="abc",string=a,flags=re.I)
# print(result)  # 返回的是一个math对象
# print(result.span())  # 拿到span的值
# print(result.group())  # 拿到match值
# # 【2】在字符串中查找，找到第一个匹配的就停
# result=re.search( "abc",a,re.I)
# print(result)
# # 【3】拆分:=re.split(pattern,string,maxsplit=0，flags=0)
# result=re.split("abc",a,flags=re.I)
# print(result)
# # 【4】替换re.sub(pattern, repl, string, count=0，flags=0)
# result=re.sub("abc","AAA",a,flags=re.I)
# print(result)
# # 【5】查找所有:findall(pattern, string, flags=0)
# result=re.findall("abc",a,re.I)
# print(result)

# input_str = input('输入用户名：')
# result = re.match('\w{6,18}',input_str)
# if result is None or len(input_str) > 18:
#     print('不合法')
# else:
#     print('合法')


# input_str = input('输入电话：')
# result = re.match('\d{3}-\d{8}',input_str)
# if result is None or len(input_str) != 12:
#     print('不合法')
# else:
#     print('合法')

# input_str = input('输入邮箱：')
# result = re.match('\w@\w.com$',input_str)
# if result is None or len(input_str) != 12:
#     print('不合法')
# else:
#     print('合法')



test_str = """<div id="s_top_wnap" class="s-top-wnap s-isindex-wrap"s<div class="s-top-nav"></div><div
class="s-center-box"></div></div><div id="s-top-left" class="s-top-left s-isindex-wnap"><a
href="http://news.baidu.com" target="_blank" class="mnav c-font-normal c-color-t">新闻</a><a
href="https://unw.hao123.com" target="_blank" class="mnav c-font-normal c-color-t">hao123</a><a
href="http://map.baidu.com" target="_blank" class="mnav c-font-normal c-color-t">地图</a><a
href="https://live.baidu.com/" target="_blank" class="mnav c-font-normal c-color-t">直播</a><a
href="https://haokan.baidu.com/?sfrom=baidu-top" target="_blank" class="mnav c-font-normal c-colon-t">视频</a><a
href="http://tieba.baidu.com" target="_blank" class="mnav c-font-normal c-color-t">贴吧</a><a
href="http://xueshu.baidu.com" target="_blank" class="mnav c-font-normal c-colon-t">学术</a><div class="mnavs-top-more-btn"><a
href="http://w.baidu.com/mone/" name="tj_briicon" class="s-bri c-font-normal c-color-t" target="_blank">更多"""
#
print(re.findall('href="(.+)?"',test_str))
#
# test_str="""[{'id':1,'name':'张飞'},{'id':22,'name':'关羽'},{'id':333,'name':'刘备'}]"""
# print(re.findall("'name':'(.+?)'",test_str))


# import time,random
# def show_time(func):
#     def calc(*args,**kwargs):
#         start_time = time.time()
#         result = func(*args,**kwargs)
#         end_time = time.time()
#         print(f"函数{func.__name__}({func.__doc__})消耗的时间是: {end_time - start_time}")
#         return result
#     return calc
# def mydec(func):
#     def show_xing(*args,**kwargs):
#         print('*'*50)
#         f = func(*args,**kwargs)
#         print('#'*50)
#         return f
#     return show_xing
#
# @mydec
# @show_time  # 语法糖
# def B():
#     time.sleep(random.randint(1,3))
#     print("完成了B任务!")
#
# @mydec
# @show_time
# def C(name,addr):
#     time.sleep(random.randint(1,3))
#     print(f"在{addr}完成了{name}任务! ")
#     return time.strftime('%Y-%m-%d %H:%M:%S')
# # show_time(B)()
# #用装饰器实现一样的功能
# # B()
# r = C('学习','成都')
# print(r)







# 写一个装饰器，能打印函数的读取时间，读取文件名，读取文件的行数。
# import time
# uname='admin'
# def role(uname):
#     def show_time(func):
#         def calc(fname):
#             if uname == 'admin':
#                 start_time = time.time()
#                 result = func(fname)
#                 end_time = time.time()
#                 print(f"读取文件：{fname}，读取行数：{len(result)}，消耗的时间: {end_time - start_time}")
#                 return result
#             else:
#                 print('没有权限')
#         return calc
#     return show_time
#
# @role(uname)
# def read(name):
#     """文件名：name"""
#     with open(name,'r',encoding='utf8') as f:
#         return f.readlines()
#
# print(read('user'))




# 迭代器
# class Fib(object):
#     def __init__(self,n):
#         self.n = n
#         self.count = 0
#         self.n1 = 0
#         self.n2 = 1
#     def __next__(self):
#         if self.count < self.n:
#             self.n1,self.n2 = self.n2,self.n1+self.n2
#             self.count += 1
#             return self.n1
#         else:
#             raise StopIteration
#     def __iter__(self):
#         return self
# f = Fib(6)
# print(next(f))
# print([i for i in Fib(10)])



# 生成器
# 做一个数列 1，2**2，3**3，4**4，。。。
# a=(i**i for i in range(1000))
# print(a)
# print(next(a))
# print(next(a))
# print(next(a))

# import time
# def mytest():
#     for i in range(1,1000):
#         result = yield i**i
#         print('mytest返回的i是',i**i,f'反馈的结果是-->{result}')
# a=mytest()
# # print(a.send('enen!'))
# print(a.send(None))
# # for i in range(5):
# #     time.sleep(1)
# #     # print(next(a))
# #     print(a.send('啊哈哈哈哈'))
#
# for i in a:
#     time.sleep(1)
#     print(i)




















































































